<?php 

if (! defined('BASEPATH')) exit('No direct script access');

class content_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function get_by_id($content_id = FALSE)
    {
        if ($content_id === FALSE)
        {
            return FALSE;
        }
        
        $query = $this->db->where('id', $content_id)
                          ->get('content');
        if ($query->num_rows() == 1)
        {
            return $query->row();
        }
        else
        {
            return FALSE;
        }
    }
    
    function get_all($num = FALSE, $offset = FALSE) 
    {
        $query = $this->db->select('*' )
                          ->order_by("id", "desc")
                          ->get('content', $num, $offset);
        return $query->result();
    }
    
    
    
    
    function create($title = FALSE, $description = FALSE)
    {
        if ($title === FALSE OR $description === FALSE )
        {
            return FALSE;
        }

        $model = array('title' => $title,
                         'description' => $description,
                         'created_date' =>date('Y-m-d H:i:s'),
                         'updated_date' =>date('Y-m-d H:i:s'),
                        );
        $this->db->insert('content', $model);
	    return $this->db->insert_id();
        
    }
    
    function update($content_id = FAlSE , $title = FALSE, $description = FALSE)
    {
        if ($content_id === FALSE OR $title === FALSE OR $description === FALSE)
        {
            return FALSE;
        }
        $model = array('title' => $title,
                         'description' => $description,
                         'updated_date' =>date('Y-m-d H:i:s'),
                        );
        $this->db->where('id', $content_id);
        $this->db->update('content', $model);
        return TRUE;
    }
    
    function delete($content_id = FALSE)
    {
        if ($content_id === FALSE)
        {
            return FALSE;
        }
        $this->db->where('id', $content_id);
        $this->db->delete('content');
        return TRUE;
    }
    
   
}
/* End of file fixture_model.php */
/* Location: ./system/application/models/fixture_model.php */